home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / JOYSTICK.SWG / 0007_Joystick Manipulation.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  2KB  |  58 lines

  1. {
  2. > I'd like to use a joystick in a program but I'm not familiar
  3. > with any algorithm to do that, suggestions?
  4.  
  5. Here's one I found lying around (public domain...<G>) on a local BBS... I
  6. changed it around a little so it would fit in one message...  It compiled into
  7. a .TPU okay, so it *probably* works.  Let me know if it doesn't... :)
  8.  
  9. --Ricky Godbee, Jr.
  10. }
  11.  
  12. unit Joystick;
  13. interface
  14. uses Dos, Crt;
  15. procedure JPos(Joystick_Number: byte; var Joystick_X, Joystick_Y: word);
  16. procedure JBut(Joystick_Number: byte; var Button_1, Button_2: boolean);
  17. implementation
  18. var Register: Registers;
  19. procedure InitRegisters;
  20. begin
  21.  FillChar(Register, Sizeof(Register), 0);
  22. end;
  23. procedure JPos(Joystick_Number: byte; var Joystick_X, Joystick_Y: word);
  24. begin
  25.  InitRegisters;
  26.  Register.AH := $84;
  27.  Register.DX := $01;
  28.  Intr($15, Register);
  29.  if Joystick_Number = 1 then
  30.   begin
  31.    Joystick_X := Register.AX;
  32.    Joystick_Y := Register.BX;
  33.   end
  34.  else if Joystick_Number = 2 then
  35.   begin
  36.    Joystick_X := Register.CX;
  37.    Joystick_Y := Register.DX;
  38.   end;
  39. end;
  40. procedure JBut(Joystick_Number: byte; var Button_1, Button_2: boolean);
  41. begin
  42.  InitRegisters;
  43.  Register.AH := $84;
  44.  Register.DX := $00;
  45.  Intr($15, Register);
  46.  case Joystick_Number of
  47.   1: begin
  48.       Button_1 := (Register.AL and $20) <> $20;
  49.       Button_2 := (Register.AL and $10) <> $10;
  50.      end;
  51.   2: begin
  52.       Button_1 := (Register.AL and $40) <> $40;
  53.       Button_2 := (Register.AL and $80) <> $80;
  54.      end;
  55.  end;
  56. end;
  57. end.
  58.